
var lists = [
    ['id','name','chlId','chlName'],
    [1,'aaa','11','saaa1'],
    [1,'aaa','12','saaa2'],
    [1,'aaa','13','saaa3'],

    [2,'bbb','21','sbbb1'],
    [2,'bbb','22','sbbb2'],
    [2,'bbb','13','sbbb3'],

    [3,'ccc','31','sccc1'],
    [3,'ccc','32','sccc2'],
    [3,'ccc','33','sccc3']
];
var param = {
    datas: lists,
    "idName" : id,
    "chl" : {
        prefix : "chl",
        "idName" : "chlId"
    },
    "chl2" : {
        prefix : "chl2",
        "idName" : "chl2Id"
    }
}
mu.table2MapHasChl(lists,'id',['chl','chl2']);

mu.table2MapHasChl = function (lists, idName, chlName) {
    mu.ctx(lists).mapKey(function (lists, itr) {
        // var mainItem = itr.item.filter(function (item, itr) {
        //     return !itr.key.startWith( chlName);
        // });
        return mu.pair(itr.item[idName], itr.item);
    }).mapReduce(function (map, itr) {
        var key = itr.key;
        var values = itr.values;



        var mainItem = values.first().filter(function (item, itr) {
            return !itr.key.startWith( chlName);
        });

        var newValues = values.map(function (map, itr) {
             itr.item.filter(function (map, itr) {
                 return itr.key.startWith(chlName);
             });
        }).mapKey(function (map, itr) {
            return mu.pair(itr.item[chlName+'Id'], itr.item);
        });

        mainItem[chlName] = newValus;

        return mu.m(itr.item[idName], mainItem);
    })

    ;
}

